package com.example.mvvmtemplate.utli.edit.filter;

import android.text.InputFilter;
import android.text.Spanned;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 只能是数字、英文
 */
public class EnglishNumberFilter implements InputFilter {

    private final Pattern pattern = Pattern.compile("[^a-zA-Z0-9]");

    @Override
    public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) {
        Matcher matcher = pattern.matcher(source);
        if (!matcher.find()) {
            return null;
        } else {
            return "";
        }
    }
}
